home *** CD-ROM | disk | FTP | other *** search
/ World of Amiga / World of Amiga.iso / archive / assembly / plasmabb.lha / PlasmaBB.s < prev   
Text File  |  1992-12-26  |  12KB  |  381 lines

  1. ***********************************************************
  2. * © 1992, Dancing Fool of Epsilon
  3. *
  4. * Using AsmOne, to make into executable:
  5. * 1. Make sure that BOOT_BLOCK is EQU'ed to 0.
  6. * 2. >a
  7. * 3. >wo miniplasma
  8. *
  9. * Using AsmOne, to put on boot block:
  10. * 1. Make sure that BOOT_BLOCK is EQU'ed to 1.
  11. * 2. >a
  12. * 3. >ws
  13. * 4. RAM_PTR> Start
  14. * 5. DISK_PTR> 0
  15. * 6. LENGTH> 2
  16. * 7. >cc
  17. *
  18. ***********************************************************
  19. * Why did I write this?
  20. *
  21. * Well, after spending several months trying to figure rgb plasma out (and
  22. * finally getting it!), I got some source to an old Masters demo that had
  23. * some zero bit plane plasma in it that looked a lot like this, only not
  24. * as good, so I decided to make a boot block out of it.  After that, I
  25. * decided to put the source out for the world to see, learn from, and laugh
  26. * at.
  27. *
  28. * How does it work?
  29. *
  30. * This code is pretty much the same a any other plasma that uses bit planes.
  31. * Zero bit plane plasma is a little bit different (and a lot faster), but looks
  32. * crappy, so who cares? :^) Anyway, I set up four bit planes of the same bit
  33. * map just a different offsets and scroll values.  Bit plane one is +4 into
  34. * the bit map and has a scroll of 4, bit plane two is +6 and scroll of $c,
  35. * bit plane 3 is +6 and scroll $c, and bit plane three is +8 and scroll of 4.
  36. * Each frame you bit in a sine wave on the bit map "stripes".  Looking
  37. * at this data shows that on any given scan line you will end up with the
  38. * following bit patterns:
  39. *
  40. * bpl1 $00ff00ffff00ff0000ff00ffff00ff0000ff00ffff00ff0000ff00ffff00ff00
  41. * bpl2 $  00ffff00ff0000ff00ffff00ff0000ff00ffff00ff0000ff00ffff00ff0000ff
  42. * bpl3 $00ffff00ff0000ff00ffff00ff0000ff00ffff00ff0000ff00ffff00ff0000ff
  43. * bpl4 $  ff00ff0000ff00ffff00ff0000ff00ffff00ff0000ff00ffff00ff0000ff00ff
  44. *
  45. * Across the scan line the color pattern is:
  46. *
  47. * color   13 6 11 5 2 9 4 10 13 6 11 5 2 9 4 10 13 6 11 5 2 9 4 10 ...
  48. *
  49. * So, even with four bitplanes only eight colors ever occour.  With this
  50. * in mind, and knowing the maximum number of copper cycles per scan line,
  51. * we know that these colors will repeat six times per raster.
  52. *
  53. * In standard plasma, which this is not, you would take the next value
  54. * from your sine table and use that as an offset into your color bar.  Then,
  55. * you blit your color bar into the first "column" of your copper list, and
  56. * repeat for the other fourty-seven (a column is a color entry).  To do rgb
  57. * plasma you would use all three blitter sources, one for each color component,
  58. * and or them all together to obtain the correct values for your copper list.
  59. *
  60. * This plasma is a little bit different.  Instead of using a horizontal sine
  61. * wave on my copper bars, I use a vertical sine wave.  This allows me to blit
  62. * an entire raster at a time.  This is a little different approach from
  63. * normal plasma, but it also takes less static space, which allows it to
  64. * easily fit on a boot block.
  65. *
  66. * Do what ever you want with this source, just don't take credit for it!
  67. * Contact me at (on InterNet):
  68. *        idr@rigel.cs.pdx.edu
  69. * Contact Epsilon at:
  70. *        Epsilon
  71. *        P.O.B. 1914
  72. *        Beaverton, OR  97075-1914
  73. *        U.S.A.
  74. ***********************************************************
  75. * Equates
  76. ***********************************************************
  77.  
  78. BOOT_BLOCK    EQU    0    ; 0 = normal executable, 1 = boot block
  79.  
  80. CUSTOM        EQU    $dff000    ; custom chip base
  81. CIA_A        EQU    $bfe001    ; cia chip for left mouse button
  82.  
  83. S_SPEED        EQU    (2<<1)    ; speed to 'scroll' copper(must be a mult of 2)
  84. S_SIZE        EQU    72    ; max scroll.  if you change the color data,
  85.                 ;   then you may need to change this too.
  86.  
  87. ROWS        EQU    180    ; number of plasma rasters (changeable)
  88. COLS        EQU    6    ; number of columns.  should be 6, but could
  89.                 ;   be less.
  90. COLORS        EQU    8    ; number of color combinations that occour.
  91. MOD        EQU    2    ; size of 'move' instruction in copper list
  92. AMP        EQU    $20    ; amplitude of sine data.  if you change the
  93.                 ;   sine data, you should change this.
  94.  
  95. MD2        EQU    (4*((COLS*COLORS)+1))    ; size of one raster of
  96.                         ;   clist data
  97. SIZE        EQU    ((64*COLS*COLORS)+1)    ; blit size for copper list
  98.  
  99. ***********************************************************
  100. * Macros
  101. ***********************************************************
  102.  
  103. WaitBlit    MACRO
  104.         tst.b    (a5)        ; ignore first test for old Agnus
  105. .\@        btst    #6,(a5)        ; test blit done bit in high byte of
  106.                     ;   DMACON
  107.         bne.b    .\@        ; loop if not done
  108.         ENDM
  109.  
  110. WaitVblank    MACRO
  111. .\@        move.l    4-2(a5),d0    ; read full beam position
  112.         andi.l    #$0003ff00,d0    ; mask of hoizontal position
  113.         cmpi.l    #$00002c00,d0    ; top of screen?
  114.         bne.b    .\@        ; not yet.
  115.         ENDM
  116.  
  117. *********************************************************************
  118.  
  119.  IFNE    BOOT_BLOCK
  120. Start:        dc.b    "DOS",0        ; boot block id long work
  121.         dc.l    0        ; checksum
  122.         dc.l    $370        ; root block
  123.  ELSE
  124.          section    plasma_bb,code_c
  125.  ENDIF
  126.  
  127. TakeSystem:
  128.         movem.l    d1-d7/a1-a6,-(sp)
  129.  IFEQ    BOOT_BLOCK
  130.         movea.l    4.w,a6        ; at boot this is already done!
  131.  ENDIF
  132.         move.l    #(size_of_list),d0
  133.         move.l    #($10003),d1    ; MEMF_CHIP | MEMF_PUBLIC | MEMF_CLEAR
  134.         jsr    -198(a6)    ; AllocMem()
  135.         tst.l    d0        ; did we get the mem?
  136.         beq.w    err_exit    ; nope.
  137.  
  138.         move.l    d0,a6        ; ptr to mem.
  139.  
  140.         lea    sine(pc),a0    ; sine table
  141.         move.l    a0,sineptr(a6)    ; initial sine ptr
  142.  
  143.         move.l    #CUSTOM+2,a5    ; Custom chip base + 2!!!
  144.  
  145.         move.w    (a5),d0        ; Save DMACON
  146.         ori.w    #$8000,d0    ; OR in the SET bit for later
  147.         move.l    a6,a0
  148.         move.w    d0,(a0)        ; Keep it
  149.         move.w    #$83c0,$96-2(a5); Turn on only certain DMA channels
  150.         move.w    #$0020,$96-2(a5); kill sprite DMA
  151.  
  152. InstallPlasmaCopper:
  153.         lea    Copper1(a6),a0    ; pointer to our copper list
  154.         move.l    a0,$80-2(a5)    ; install it
  155.     
  156.         move.w    #$00e0,d0    ; bpl1pth
  157.         moveq    #7,d1        ; loop counter
  158. .make_bplpt:    move.w    d0,(a0)+    ; write it to our copper list
  159.         addq.w    #2,a0        ; next in list
  160.         addq.w    #2,d0        ; next value
  161.         dbra    d1,.make_bplpt    ; loop
  162.     
  163.         sub.w    #30,a0        ; a0 points to mapptrs + 2
  164.  
  165.         move.l    a6,d0        ; data segment
  166.         add.l    #PBmap+4,d0    ; plasma map plus a bit
  167.  
  168.         move.w    d0,4(a0)    ; bpl1ptl
  169.         swap    d0        ; high word in low half of register
  170.         move.w    d0,(a0)        ; bpl1pth
  171.  
  172.         swap    d0        ; swap back
  173.         addq.l    #2,d0        ; in a bit more
  174.         move.w    d0,12(a0)    ; bpl2ptl
  175.         move.w    d0,20(a0)    ; bpl3ptl
  176.         swap    d0        ; high word in low word
  177.         move.w    d0,8(a0)    ; bpl2pth
  178.         move.w    d0,16(a0)    ; bpl3pth
  179.  
  180.         swap    d0        ; swap back
  181.         addq.l    #2,d0        ; in some more
  182.         move.w    d0,28(a0)    ; bpl4ptl
  183.         swap    d0        ; guess why I do this. :^)
  184.         move.w    d0,24(a0)    ; bpl4pth
  185.  
  186.         lea    plasma_copper1(a6),a0    ; raster data
  187.     
  188.         move.l    #$2d1ffffe,d1    ; starting raster - 1
  189.         move.w    #ROWS-1,d5    ; number of rasters
  190. m_plasma1:    add.l    #$01000000,d1    ; next raster
  191.         move.l    d1,(a0)+    ; write raster wait to clist
  192.         moveq    #COLS-1,d4    ; number of columns
  193. m_plasma2:    move.w    #$019a,(a0)+    ; write each color out to clist
  194.         addq.w    #2,a0        ; next entry
  195.         move.w    #$018c,(a0)+
  196.         addq.w    #2,a0
  197.         move.w    #$0196,(a0)+
  198.         addq.w    #2,a0
  199.         move.w    #$018a,(a0)+
  200.         addq.w    #2,a0
  201.         move.w    #$0184,(a0)+
  202.         addq.w    #2,a0
  203.         move.w    #$0192,(a0)+
  204.         addq.w    #2,a0
  205.         move.w    #$0188,(a0)+
  206.         addq.w    #2,a0
  207.         move.w    #$0194,(a0)+
  208.         addq.w    #2,a0
  209.         dbra    d4,m_plasma2    ; loop for columns
  210.         dbra    d5,m_plasma1    ; loop for rasters
  211.  
  212.         moveq    #-2,d0        ; end of clist
  213.         move.l    d0,(a0)        ; write it out
  214.  
  215.         moveq    #0,d4
  216.  
  217.     ; the following are not in the clist to save space
  218.         move.w    #$4200,$100-2(a5)    ; bplcon0 (4 bit planes)
  219.         move.w    #$00c4,$102-2(a5)    ; fine scroll
  220.         moveq    #$0008,d0        ; modulo value
  221.         move.w    d0,$0108-2(a5)        ; write to clist
  222.         move.w    d0,$010a-2(a5)        ; ...
  223.         move.w    #$2e78,$8e-2(a5)    ; window start
  224.         move.w    #$e2c6,$90-2(a5)    ; window stop
  225.         move.w    #$0028,$92-2(a5)    ; data fetch start
  226.         move.w    #$00d8,$94-2(a5)    ; data fetch stop
  227.  
  228. Plasm2:        WaitVblank
  229.         lea    PBmap(a6),a0        ; bit map
  230.         move.l    sineptr(a6),a4        ; pointer to sine table
  231.         lea    stripes(pc),a2        ; "stripe data"
  232.         move.l    a6,d2            ; data seg
  233.         add.l    #plasma_copper1+6,d2    ; raster data
  234.  
  235.         move.w    #ROWS-1,d0    ; loop counter
  236.         move.l    #$09f00000,d3    ; bltcon0 & bltcon1
  237.         moveq    #$f,d5        ; mask off upper bits
  238.         moveq    #64+26,d6    ; blit window
  239.  
  240. map_top:    tst.b    (a4)        ; is it -1 ($ff)?
  241.         bpl.b    .no_sine_reset    ; nope
  242.         lea    sine(pc),a4    ; reset sine pointer
  243. .no_sine_reset:    WaitBlit        ; wait for it...
  244.  
  245.         move.l    a0,a3        ; ptr to bit map
  246.  
  247.     ; you can replace this with a move.b (a4),d1 and see what happens
  248.         moveq    #AMP,d1        ; amplitude of sine wave
  249.         sub.b    (a4),d1        ; less sine value
  250.  
  251.         lsr.w    #4,d1        ; divide by 16 (nearest word offset)
  252.         add.w    d1,d1        ; word offset
  253.         add.w    d1,a3        ; add to bit map pointer
  254.     
  255.     ; if you made above into a move.b (a4),d1 then do it here, too.
  256.         moveq    #AMP,d1        ; amplitude of sine wave
  257.         sub.b    (a4),d1        ; less sine value
  258.  
  259.         and.l    d5,d1        ; mask off upper bits to make into
  260.                     ; shift value
  261.         ror.l    #4,d1        ; put shift value in high nibble
  262.         or.l    d3,d1        ; or into bplcon
  263.  
  264.     ; I'm only doing one line at a time, so the modulos
  265.     ;   are irrelevant.
  266.         move.l    d1,$40-2(a5)    ; bltcon0 & bltcon1
  267.         move.l    #-1,$44-2(a5)    ; first word mask
  268.         movem.l    a2/a3,$50-2(a5)    ; source
  269.         move.w    d6,$58-2(a5)    ; blit window
  270.  
  271.         adda.w    #54,a0        ; next raster in bit map
  272.  
  273.         lea    color_list(pc),a1 ; Get start of color lists.
  274.         move.b    (a4)+,d1    ; sine value (again!)
  275.         add.w    d1,d1        ; word align.
  276.         add.w    d4,a1        ; gives copper a cool 'scrolly' effect
  277.                     ;   try removing.
  278.         add.w    d1,a1        ; new position in color table (sine)
  279.  
  280.         moveq    #MOD,d1        ; in the clist, this is how big the
  281.                     ; first part of the 'move' is.
  282.         WaitBlit
  283.         move.l    d3,$40-2(a5)    ; bltcon0 & bltcon1
  284.         move.l    d1,$64-2(a5)    ; dest mod.
  285.         move.l    a1,$50-2(a5)    ; source A
  286.         move.l    d2,$54-2(a5)    ; dest.
  287.         move.w    #SIZE,$58-2(a5)    ; bltsize
  288.  
  289.         add.l    #MD2,d2        ; Next color in copper list.
  290.         dbra    d0,map_top    ; loop
  291.  
  292. end_frame:    lea    sineptr(a6),a1    ; old sine ptr
  293.         addq.l    #1,(a1)        ; next place in sine table
  294.     
  295.         move.l    (a1),a1        ; new sine ptr
  296.         tst.b    (a1)        ; is it -1?
  297.         bpl.b    .no_sine_reset    ; no.
  298.         lea    sine(pc),a4    ; reset sine pointer
  299.         move.l    a4,sineptr(a6)    ; reset sine prt
  300.  
  301. .no_sine_reset:    addq.w    #(S_SPEED),d4    ; scroll speed
  302.         cmpi.w    #(S_SIZE),d4    ; past scroll limit?
  303.         blt.b    .no_scroll_reset
  304.         moveq    #0,d4        ; reset copper scrolly value
  305.  
  306. .no_scroll_reset:
  307.         btst.b    #6,CIA_A    ; is lmb down?
  308.         bne.w    Plasm2        ; not yet...
  309.  
  310.         move.l    a6,a4
  311.         movea.l    4.w,a6            ; ExecBase
  312.         lea    GraphicsName(pc),a1    ; "graphics.library"
  313.         jsr    -$198(a6)        ; OldOpenLibrary()
  314.         move.l    d0,a1            ; Copy ptr to GfxBase
  315.         move.l    $26(a1),$80-2(a5)    ; Install old system copperlist
  316.         jsr    -$19e(a6)        ; CloseLibrary()
  317.  
  318.         move.l    a4,a1
  319.         move.w    #$7fff,$96-2(a5)    ; Kill all DMA!
  320.         move.w    (a1),$96-2(a5)        ; Activate old DMA channels
  321.  
  322.         move.l    #(size_of_list),d0    ; size of block
  323.         jsr    -$d2(a6)        ; Free()
  324.  
  325. err_exit:    lea    DosName(pc),a1    ; pointer to lib. name
  326.         jsr    -$60(a6)    ; FindResident()
  327.         tst.l    d0        ; error?
  328.         beq.b    .error        ; yes.
  329.         move.l    d0,a0        ; ptr to dos base
  330.         move.l    $16(a0),a0    ; pointer to dos lib
  331.         moveq    #0,d0        ; return no error
  332. .exit:        movem.l    (sp)+,d1-d7/a1-a6
  333.         rts            ; Done
  334.  
  335. .error:        moveq    #-1,d0        ; error code
  336.         bra.b    .exit
  337.  
  338. ***********************************************************    
  339.  
  340. stripes:dc.l    $00ff00ff,$ff00ff00,$00ff00ff,$ff00ff00,$00ff00ff,$ff00ff00
  341.     dc.l    $00ff00ff,$ff00ff00,$00ff00ff,$ff00ff00,$00ff00ff,$ff00ff00
  342.     dc.l    $00ff00ff
  343.  
  344. color_list:
  345.     dc.l    $ff00ff0,$fe10fd2,$fc30fb4,$fa50f96,$f870f78,$f690f5a
  346.     dc.l    $f4b0f3c,$f2d0f1e,$f0f0f0f,$f0f0f0f,$f1e0f2d,$f3c0f4b
  347.     dc.l    $f5a0f69,$f780f87,$f960fa5,$fb40fc3,$fd20fe1,$ff00ff0
  348.     dc.l    $ff00ff0,$fe10fd2,$fc30fb4,$fa50f96,$f870f78,$f690f5a
  349.     dc.l    $f4b0f3c,$f2d0f1e,$f0f0f0f,$f0f0f0f,$f1e0f2d,$f3c0f4b
  350.     dc.l    $f5a0f69,$f780f87,$f960fa5,$fb40fc3,$fd20fe1,$ff00ff0
  351.     dc.l    $ff00ff0,$fe10fd2,$fc30fb4,$fa50f96,$f870f78,$f690f5a
  352.     dc.l    $f4b0f3c,$f2d0f1e,$f0f0f0f,$f0f0f0f,$f1e0f2d,$f3c0f4b
  353.     dc.l    $f5a0f69,$f780f87,$f960fa5,$fb40fc3,$fd20fe1,$ff00ff0
  354.     dc.l    $ff00ff0,$fe10fd2,$fc30fb4,$fa50f96
  355.  
  356. ; Sine table MUST end with a $ff!
  357. sine:    dc.l    $10111213,$14161718,$191a1b1c,$1c1d1e1e,$1f1f1f1f,$1f1f1f1f
  358.     dc.l    $1f1e1e1d,$1d1c1b1a,$19181716,$15141311,$10100f0e,$0c0b0a09
  359.     dc.l    $08070605,$04030302,$02010101,$01010101,$01010202,$03040405
  360.     dc.w    $0607,$0809,$0a0b,$0d0e,$0fff
  361.  
  362. GraphicsName:    dc.b    'graphics.library',0
  363. DosName:    dc.b    'dos.library',0
  364.  
  365. message:    dc.b    "Not a virus! A plasma bb by the DF of Epsilon!"
  366.  
  367. *********************************************************************
  368.  
  369.         rsreset
  370. DMACONSave    rs.w    1        ; save DMA bits here
  371. sineptr        rs.l    1
  372.  
  373. PBmap        rs.b    54*ROWS+100    ; plasma bit map
  374.  
  375. Copper1        rs.b    0        ; start of copper list
  376. mapptrs        rs.w    16        ; bmap pointer
  377. plasma_copper1    rs.b    (4*(ROWS*(1+(COLS*COLORS))))    ; raster data
  378. pe_1        rs.w    2        ; end of clist
  379.  
  380. size_of_list    rs.b    0        ; duh! :^)
  381.